 package tools.packet;

 import client.MapleCharacter;
 import handling.opcode.SendPacketOpcode;
 import handling.world.WorldFamilyService;
 import handling.world.family.MapleFamily;
 import handling.world.family.MapleFamilyBuff;
 import handling.world.family.MapleFamilyCharacter;
 import java.util.Iterator;
 import java.util.List;
 import tools.data.output.MaplePacketLittleEndianWriter;

 public class FamilyPacket
 {
   public static byte[] getFamilyData() {
/*  16 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/*  18 */     mplew.writeShort(SendPacketOpcode.FAMILY.getValue());
/*  19 */     MapleFamilyBuff[] entries = MapleFamilyBuff.values();
/*  20 */     mplew.writeInt(entries.length);

/*  22 */     for (MapleFamilyBuff entry : entries) {
/*  23 */       mplew.write(entry.type);
/*  24 */       mplew.writeInt(entry.rep);
/*  25 */       mplew.writeInt(1);
/*  26 */       mplew.writeMapleAsciiString(entry.name);
/*  27 */       mplew.writeMapleAsciiString(entry.desc);
     }
/*  29 */     return mplew.getPacket();
   }




   public static byte[] changeRep(int r, String name) {
/*  36 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
/*  37 */     mplew.writeShort(SendPacketOpcode.REP_INCREASE.getValue());
/*  38 */     mplew.writeInt(r);
/*  39 */     mplew.writeMapleAsciiString(name);
/*  40 */     return mplew.getPacket();
   }




   public static byte[] getFamilyInfo(MapleCharacter chr) {
/*  47 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
/*  48 */     mplew.writeShort(SendPacketOpcode.OPEN_FAMILY.getValue());
/*  49 */     mplew.writeInt(chr.getCurrentRep());
/*  50 */     mplew.writeInt(chr.getTotalRep());
/*  51 */     mplew.writeInt(chr.getTotalRep());
/*  52 */     mplew.writeShort(chr.getNoJuniors());
/*  53 */     mplew.writeShort(2);
/*  54 */     mplew.writeShort(chr.getNoJuniors());
/*  55 */     MapleFamily family = WorldFamilyService.getInstance().getFamily(chr.getFamilyId());
/*  56 */     if (family != null) {
/*  57 */       mplew.writeInt(family.getLeaderId());
/*  58 */       mplew.writeMapleAsciiString(family.getLeaderName());
/*  59 */       mplew.writeMapleAsciiString(family.getNotice());
     } else {
/*  61 */       mplew.writeLong(0L);
     }
/*  63 */     List<Integer> b = chr.usedBuffs();
/*  64 */     mplew.writeInt(b.size());
/*  65 */     for (Iterator<Integer> iterator = b.iterator(); iterator.hasNext(); ) { int ii = ((Integer)iterator.next()).intValue();
/*  66 */       mplew.writeInt(ii);
/*  67 */       mplew.writeInt(1); }

/*  69 */     return mplew.getPacket();
   }

   public static void addFamilyCharInfo(MapleFamilyCharacter ldr, MaplePacketLittleEndianWriter mplew) {
/*  73 */     mplew.writeInt(ldr.getId());
/*  74 */     mplew.writeInt(ldr.getSeniorId());
/*  75 */     mplew.writeInt(ldr.getJobId());
/*  76 */     mplew.write(ldr.getLevel());
/*  77 */     mplew.write(ldr.isOnline() ? 1 : 0);
/*  78 */     mplew.writeInt(ldr.getCurrentRep());
/*  79 */     mplew.writeInt(ldr.getTotalRep());
/*  80 */     mplew.writeInt(ldr.getTotalRep());
/*  81 */     mplew.writeInt(ldr.getTotalRep());
/*  82 */     mplew.writeLong(Math.max(ldr.getChannel(), 0));
/*  83 */     mplew.writeMapleAsciiString(ldr.getName());
   }




   public static byte[] getFamilyPedigree(MapleCharacter chr) {
/*  90 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
/*  91 */     mplew.writeShort(SendPacketOpcode.SEND_PEDIGREE.getValue());
/*  92 */     mplew.writeInt(chr.getId());
/*  93 */     MapleFamily family = WorldFamilyService.getInstance().getFamily(chr.getFamilyId());
/*  94 */     int gens = 0, generations = 0;
/*  95 */     if (family == null) {
/*  96 */       mplew.writeInt(2);
/*  97 */       addFamilyCharInfo(new MapleFamilyCharacter(chr, 0, 0, 0, 0), mplew);
     } else {
/*  99 */       mplew.writeInt(family.getMFC(chr.getId()).getPedigree().size() + 1);
/* 100 */       addFamilyCharInfo(family.getMFC(family.getLeaderId()), mplew);

/* 102 */       if (chr.getSeniorId() > 0) {
/* 103 */         MapleFamilyCharacter senior = family.getMFC(chr.getSeniorId());
/* 104 */         if (senior != null) {
/* 105 */           if (senior.getSeniorId() > 0) {
/* 106 */             addFamilyCharInfo(family.getMFC(senior.getSeniorId()), mplew);
           }
/* 108 */           addFamilyCharInfo(senior, mplew);
         }
       }
     }
/* 112 */     addFamilyCharInfo((chr.getMFC() == null) ? new MapleFamilyCharacter(chr, 0, 0, 0, 0) : chr.getMFC(), mplew);
/* 113 */     if (family != null) {
/* 114 */       if (chr.getSeniorId() > 0) {
/* 115 */         MapleFamilyCharacter senior = family.getMFC(chr.getSeniorId());
/* 116 */         if (senior != null) {
/* 117 */           if (senior.getJunior1() > 0 && senior.getJunior1() != chr.getId()) {
/* 118 */             addFamilyCharInfo(family.getMFC(senior.getJunior1()), mplew);
/* 119 */           } else if (senior.getJunior2() > 0 && senior.getJunior2() != chr.getId()) {
/* 120 */             addFamilyCharInfo(family.getMFC(senior.getJunior2()), mplew);
           }
         }
       }
/* 124 */       if (chr.getJunior1() > 0) {
/* 125 */         MapleFamilyCharacter junior = family.getMFC(chr.getJunior1());
/* 126 */         if (junior != null) {
/* 127 */           addFamilyCharInfo(junior, mplew);
         }
       }
/* 130 */       if (chr.getJunior2() > 0) {
/* 131 */         MapleFamilyCharacter junior = family.getMFC(chr.getJunior2());
/* 132 */         if (junior != null) {
/* 133 */           addFamilyCharInfo(junior, mplew);
         }
       }
/* 136 */       if (chr.getJunior1() > 0) {
/* 137 */         MapleFamilyCharacter junior = family.getMFC(chr.getJunior1());
/* 138 */         if (junior != null) {
/* 139 */           if (junior.getJunior1() > 0 && family.getMFC(junior.getJunior1()) != null) {
/* 140 */             gens++;
/* 141 */             addFamilyCharInfo(family.getMFC(junior.getJunior1()), mplew);
           }
/* 143 */           if (junior.getJunior2() > 0 && family.getMFC(junior.getJunior2()) != null) {
/* 144 */             gens++;
/* 145 */             addFamilyCharInfo(family.getMFC(junior.getJunior2()), mplew);
           }
         }
       }
/* 149 */       if (chr.getJunior2() > 0) {
/* 150 */         MapleFamilyCharacter junior = family.getMFC(chr.getJunior2());
/* 151 */         if (junior != null) {
/* 152 */           if (junior.getJunior1() > 0 && family.getMFC(junior.getJunior1()) != null) {
/* 153 */             gens++;
/* 154 */             addFamilyCharInfo(family.getMFC(junior.getJunior1()), mplew);
           }
/* 156 */           if (junior.getJunior2() > 0 && family.getMFC(junior.getJunior2()) != null) {
/* 157 */             gens++;
/* 158 */             addFamilyCharInfo(family.getMFC(junior.getJunior2()), mplew);
           }
         }
       }
/* 162 */       generations = family.getMemberSize();
     }
/* 164 */     mplew.writeLong((2 + gens));
/* 165 */     mplew.writeInt(gens);
/* 166 */     mplew.writeInt(-1);
/* 167 */     mplew.writeInt(generations);
/* 168 */     if (family != null) {
/* 169 */       if (chr.getJunior1() > 0) {
/* 170 */         MapleFamilyCharacter junior = family.getMFC(chr.getJunior1());
/* 171 */         if (junior != null) {
/* 172 */           if (junior.getJunior1() > 0 && family.getMFC(junior.getJunior1()) != null) {
/* 173 */             mplew.writeInt(junior.getJunior1());
/* 174 */             mplew.writeInt(family.getMFC(junior.getJunior1()).getDescendants());
           }
/* 176 */           if (junior.getJunior2() > 0 && family.getMFC(junior.getJunior2()) != null) {
/* 177 */             mplew.writeInt(junior.getJunior2());
/* 178 */             mplew.writeInt(family.getMFC(junior.getJunior2()).getDescendants());
           }
         }
       }
/* 182 */       if (chr.getJunior2() > 0) {
/* 183 */         MapleFamilyCharacter junior = family.getMFC(chr.getJunior2());
/* 184 */         if (junior != null) {
/* 185 */           if (junior.getJunior1() > 0 && family.getMFC(junior.getJunior1()) != null) {
/* 186 */             mplew.writeInt(junior.getJunior1());
/* 187 */             mplew.writeInt(family.getMFC(junior.getJunior1()).getDescendants());
           }
/* 189 */           if (junior.getJunior2() > 0 && family.getMFC(junior.getJunior2()) != null) {
/* 190 */             mplew.writeInt(junior.getJunior2());
/* 191 */             mplew.writeInt(family.getMFC(junior.getJunior2()).getDescendants());
           }
         }
       }
     }
/* 196 */     List<Integer> b = chr.usedBuffs();
/* 197 */     mplew.writeInt(b.size());
/* 198 */     for (Iterator<Integer> iterator = b.iterator(); iterator.hasNext(); ) { int ii = ((Integer)iterator.next()).intValue();
/* 199 */       mplew.writeInt(ii);
/* 200 */       mplew.writeInt(1); }

/* 202 */     mplew.writeShort(2);
/* 203 */     return mplew.getPacket();
   }

   public static byte[] sendFamilyInvite(int cid, int otherLevel, int otherJob, String inviter) {
/* 207 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 209 */     mplew.writeShort(SendPacketOpcode.FAMILY_INVITE.getValue());
/* 210 */     mplew.writeInt(cid);
/* 211 */     mplew.writeInt(otherLevel);
/* 212 */     mplew.writeInt(otherJob);
/* 213 */     mplew.writeInt(0);
/* 214 */     mplew.writeMapleAsciiString(inviter);

/* 216 */     return mplew.getPacket();
   }

   public static byte[] getSeniorMessage(String name) {
/* 220 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
/* 221 */     mplew.writeShort(SendPacketOpcode.SENIOR_MESSAGE.getValue());
/* 222 */     mplew.writeMapleAsciiString(name);
/* 223 */     return mplew.getPacket();
   }




   public static byte[] sendFamilyJoinResponse(boolean accepted, String added) {
/* 230 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
/* 231 */     mplew.writeShort(SendPacketOpcode.FAMILY_JUNIOR.getValue());




/* 236 */     mplew.write(accepted ? 1 : 0);
/* 237 */     mplew.writeMapleAsciiString(added);
/* 238 */     return mplew.getPacket();
   }

   public static byte[] familyBuff(int type, int buffnr, int amount, int time) {
/* 242 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
/* 243 */     mplew.writeShort(SendPacketOpcode.FAMILY_BUFF.getValue());
/* 244 */     mplew.write(type);
/* 245 */     if (type >= 2 && type <= 4) {
/* 246 */       mplew.writeInt(buffnr);

/* 248 */       mplew.writeInt((type == 3) ? 0 : amount);
/* 249 */       mplew.writeInt((type == 2) ? 0 : amount);
/* 250 */       mplew.write(0);
/* 251 */       mplew.writeInt(time);
     }
/* 253 */     return mplew.getPacket();
   }

   public static byte[] cancelFamilyBuff() {
/* 257 */     return familyBuff(0, 0, 0, 0);
   }




   public static byte[] familyLoggedIn(boolean online, String name) {
/* 264 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
/* 265 */     mplew.writeShort(SendPacketOpcode.FAMILY_LOGGEDIN.getValue());
/* 266 */     mplew.write(online ? 1 : 0);
/* 267 */     mplew.writeMapleAsciiString(name);
/* 268 */     return mplew.getPacket();
   }

   public static byte[] familySummonRequest(String name, String mapname) {
/* 272 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
/* 273 */     mplew.writeShort(SendPacketOpcode.FAMILY_USE_REQUEST.getValue());
/* 274 */     mplew.writeMapleAsciiString(name);
/* 275 */     mplew.writeMapleAsciiString(mapname);
/* 276 */     return mplew.getPacket();
   }




   public static byte[] sendFamilyMessage(int op) {
/* 283 */     return sendFamilyMessage(op, 0);
   }

   public static byte[] sendFamilyMessage(int op, int id) {
/* 287 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();













/* 301 */     mplew.writeShort(SendPacketOpcode.FAMILY_MESSAGE.getValue());
/* 302 */     mplew.writeInt(op);
/* 303 */     mplew.writeInt(id);

/* 305 */     return mplew.getPacket();
   }
 }


/* Location:              C:\PGX\Server.jar!\tools\packet\FamilyPacket.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */